            
class LifeNoteController 
{

    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [save:'POST', update:'POST']

    def list = 
    {
    	def flag = params.flag;
        if(!params.max) params.max = 10;
        if(!params.offset) params.offset = 0;
        def nametj = "";
        def lifeNoteInstanceList = [];
        def totalRow;   
        if(params.nametj)
        	nametj = params.nametj;
        if(nametj && nametj != "")
        {
        	if(params.sort && params.order)
        	{
        		lifeNoteInstanceList = LifeNote.findAll("from LifeNote where title like '%${nametj}%' and flag='${params.flag}' order by ${params.sort} ${params.order} ", [max:params.max.toInteger(), offset:params.offset.toInteger()]);
        	}else
        	{
        		lifeNoteInstanceList = LifeNote.findAll("from LifeNote where title like '%${nametj}%' and flag='${params.flag}' order by ordernum", [max:params.max.toInteger(), offset:params.offset.toInteger()]);
        	}
        	totalRow = LifeNote.executeQuery("select count(*) from LifeNote where title like '%${nametj}%' and flag='${params.flag}'"); 
        	totalRow = totalRow[0];      	
        }else
        {
        	if(params.sort && params.order)
        	{
        		lifeNoteInstanceList = LifeNote.findAll("from LifeNote where flag='${params.flag}' order by ${params.sort} ${params.order} ", [max:params.max.toInteger(), offset:params.offset.toInteger()]);
        	}else
        	{
        		lifeNoteInstanceList = LifeNote.findAll("from LifeNote where flag='${params.flag}' order by ordernum", [max:params.max.toInteger(), offset:params.offset.toInteger()]);
        	}
        	totalRow  = LifeNote.executeQuery("select count(*) from LifeNote where flag='${params.flag}'");
        	totalRow = totalRow[0];
        }
        
        return [ lifeNoteInstanceList:lifeNoteInstanceList, totalRow:totalRow, nametj:nametj, max:params.max, offset:params.offset, sort:params.sort, order:params.order, flag:flag ]
    }
    

    def show = 
    {
        def lifeNoteInstance = LifeNote.get( params.id )

        if(!lifeNoteInstance) 
        {
            flash.message = message(code:'lxh.display.noFindMsg')
            redirect(action:list)
        }
        else { return [ lifeNoteInstance : lifeNoteInstance ] }
    }

    def delete = 
    {
        def lifeNoteInstance = LifeNote.get( params.id )
        if(lifeNoteInstance) 
        {
            lifeNoteInstance.delete()
            flash.message = message(code:'lxh.display.deleteMsg')
            redirect(action:list, params:[flag:params.flag])
        }else 
        {
            flash.message = message(code:'lxh.display.noFindMsg')
            redirect(action:list, params:[flag:params.flag])
        }
    }

    def edit = 
    {
        def lifeNoteInstance = LifeNote.get( params.id )

        if(!lifeNoteInstance) 
        {
            flash.message = message(code:'lxh.display.noFindMsg')
            redirect(action:list, params:[flag:params.flag])
        }else 
        {
            return [ lifeNoteInstance : lifeNoteInstance, flag:params.flag ]
        }
    }

    def update = 
    {
        def lifeNoteInstance = LifeNote.get( params.id )
        if(lifeNoteInstance) 
        {
            lifeNoteInstance.properties = params
            lifeNoteInstance.lastUpdateDate = new Date();
            if(!lifeNoteInstance.hasErrors() && lifeNoteInstance.save()) 
            {
                flash.message = message(code:'lxh.display.updateMsg')
                redirect(action:list, params:[flag:params.flag])
            }else 
            {
                render(view:'edit',model:[lifeNoteInstance:lifeNoteInstance,flag:params.flag])
            }
        }else 
        {
            flash.message = message(code:'lxh.display.noFindMsg')
            redirect(action:edit,id:params.id, params:[flag:params.flag])
        }
    }

    def create = 
    {
        def lifeNoteInstance = new LifeNote()
        lifeNoteInstance.properties = params
        return ['lifeNoteInstance':lifeNoteInstance, flag:params.flag]
    }

    def save = 
    {
        def lifeNoteInstance = new LifeNote(params)
        lifeNoteInstance.flag = params.flag;
        lifeNoteInstance.createDate = new Date();
        lifeNoteInstance.lastUpdateDate = new Date();
        if(!lifeNoteInstance.hasErrors() && lifeNoteInstance.save()) 
        {
            flash.message = message(code:'lxh.display.createMsg')
            redirect(action:list,params:[flag:params.flag])
        }else 
        {
            render(view:'create',model:[lifeNoteInstance:lifeNoteInstance,flag:params.flag])
        }
    }
    
}